#define _CRT_SECURE_NO_WARNINGS
#include"Date.h"
 Date::Date(int year, int month , int day )
{
	_year = year;
	_month = month;
	_day = day;
}
void Date::Printf()
{	
	cout << _year << '-' << _month << '-' << _day << endl;
}
Date& Date::operator+=(int day)
{
	_day += day;
	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		_month++;
		if (_month == 13)
		{
			_year++;
			_month = 1;
		}
	}
	return *this;
}
Date Date::operator+(int day)
{
	Date time = *this;
	time += day;
	/*time._day += day;
	while (time._day > GetMonthDay(time._year, time._month))
	{
		time._day -= GetMonthDay(time._year, time._month);
		time._month++;
		if (time._month == 13)
		{
			time._year++;
			time._month = 1;
		}
	}*/
	return time;
}
Date& Date::operator-=(int day)
{
	//*this =*this-day;
	_day -= day;
	while (_day <= 0)
	{
		_month--;
		if (_month == 0)
		{
			_month = 12;
			_year--;
		}
		_day += GetMonthDay(_year, _month);
	}
	return *this;
}
Date Date::operator-(int day)
{
	Date time = *this;
	time -= day;
	return time;
}
